
<div id="main-wrapper">
	<h1>管理讲座</h1>

	<form id="form-enter">
		<div class="form-group">
			<div class="input-group">
				<input type="text" class="form-control" name="lkey" placeholder="讲座序列号">
				<span class="input-group-btn">
					<button class="btn btn-primary" href="#/open">开启讲座</button>
				</span>
			</div>
		</div>
		<div class="form-group">
			<input type="password" class="form-control" name="lpwd" placeholder="输入密码">
		</div>
		<div class="form-group">
			<div class="input-group">
				<input type="text" class="form-control" name="vcode" placeholder="验证码">
				<span class="input-group-addon">
					<canvas id="canvas-vcode" width="70" height="18"></canvas>
				</span>
			</div>
		</div>
		<div class="form-group">
			<button type="submit" class="btn btn-primary btn-lg btn-block">
				管理讲座
			</button>
		</div>
	</form>
</div>


<script>
	var $formEnter = $('#form-enter'),
		$canvasVcode = $('#canvas-vcode');

	$formEnter.ajaxForm({
		type: 'post',
		url: '/do/s/enter',
		success: function(resObj) {
            var ok = resObj['ok'], msg = resObj['msg'];
            msg && notify(msg, ok);
			if (ok) {
				loadFrame('#/view');
				updateNavbar();
			} else {
				showValicode();
				$formOpen.find('[name="vcode"]').val('');
			}
		}
	});

	showValicode();

	function showValicode() {
		$.get('/do/vcode?action=enter', function(resObj) {
			$.get('/do/vcode?action=enter', function(resObj) {
				if (! resObj['ok']) {
					return notify('获取验证码失败', 0);
				}
				var vcodeInfo = resObj['vcodeInfo'],
					num1 = vcodeInfo['num1'],
					num2 = vcodeInfo['num2'],
					oper = vcodeInfo['oper'];
				$canvasVcode.drawVerificationCode(num1, num2, oper);
			});
		});
	}
</script>